package cc.rengu.redp.bizimpl.upmp.service.impl;

import cc.rengu.redp.bizimpl.upmp.dao.TBCreditInvestigationMapper;
import cc.rengu.redp.bizimpl.upmp.domain.TBCreditInvestigation;
import cc.rengu.redp.bizimpl.upmp.domain.TBOnlineVerification;
import cc.rengu.redp.bizimpl.upmp.service.ITBCreditInvestigationService;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.utils.SortUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author System
 * @since 2022-05-02
 */
@Service
public class TBCreditInvestigationServiceImpl extends ServiceImpl<TBCreditInvestigationMapper, TBCreditInvestigation> implements ITBCreditInvestigationService {
    @Override
    public IPage<TBCreditInvestigation> findByPage(QueryRequest request, TBCreditInvestigation info) {

        try {
            LambdaQueryWrapper<TBCreditInvestigation> queryWrapper = new LambdaQueryWrapper<>();
            if (StringUtils.isNotBlank(info.getInstId())) {
                queryWrapper.like(TBCreditInvestigation::getInstId, info.getInstId());
            }
            if (StringUtils.isNotBlank(info.getMchntNo())) {
                queryWrapper.like(TBCreditInvestigation::getMchntNo, info.getMchntNo());
            }
            if (StringUtils.isNotBlank(info.getCheckInst())) {
                queryWrapper.like(TBCreditInvestigation::getCheckInst, info.getCheckInst());
            }
            if (StringUtils.isNotBlank(info.getMchntName())) {
                queryWrapper.like(TBCreditInvestigation::getMchntName, info.getMchntName());
            }
            if (StringUtils.isNotBlank(info.getCheckPerson())) {
                queryWrapper.like(TBCreditInvestigation::getCheckPerson, info.getCheckPerson());
            }
            queryWrapper.orderByDesc(TBCreditInvestigation::getCreateTime);

            Page<TBCreditInvestigation> page = new Page<>();
            SortUtil.handlePageSort(request, page, true);
            return this.page(page,queryWrapper);
        } catch (Exception e) {
            log.error("查询失败", e);
            return null;
        }
    }
}
